package com.feemanage.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.common.annotation.Anonymous;
import com.common.core.domain.R;
import com.common.core.page.PageDomain;
import com.common.core.page.TableDataInfo;
import com.common.utils.poi.ExcelUtil;
import com.common.validate.add;
import com.common.validate.edit;
import com.feemanage.domain.BizProjectIncome;
import com.feemanage.domain.bo.FundsFeeShowBo;
import com.feemanage.domain.bo.ProjectIncomeShowBo;
import com.feemanage.domain.vo.BizProjectInComeVo;
import com.feemanage.domain.vo.ProjectIncomeShowVo;
import com.feemanage.service.IBizProjectIncomeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import java.util.Arrays;
import java.util.List;

/**
 * 经费卡入账
 */
@Api(tags="经费卡入账")
@RestController
@RequestMapping("/feemanage/proincome")
public class BizProjectIncomeController {

    @Autowired
    private IBizProjectIncomeService baseService;

    /**
     * 查询列表
     * @param pageDomain
     * @param income
     * @return
     */
    @ApiOperation("查询列表")
    @GetMapping("/list")
    public TableDataInfo list(PageDomain pageDomain, BizProjectIncome income){
        IPage<BizProjectInComeVo> page = baseService.selectList(pageDomain,income);
        return TableDataInfo.build(page.getRecords(),page.getTotal());
    }

    @ApiOperation("导出经费卡入账")
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody PageDomain pageDomain,  @RequestBody BizProjectIncome income)
    {
        List<BizProjectInComeVo> list = baseService.selectExportList(pageDomain,income);
        ExcelUtil<BizProjectInComeVo> util = new ExcelUtil<>(BizProjectInComeVo.class);
        util.exportExcel(response, list, "经费卡入账","经费卡入账");
    }


    /**
     * 新增
     * @param income
     * @return
     */
    @PostMapping("/add")
    public R<Void> addProIncome(@Validated(add.class) @RequestBody ProjectIncomeShowBo income){
        boolean result = baseService.addProIncome(income);
        return result ? R.ok() : R.fail();
    }

    /**
     * 编辑
     * @param income
     * @return
     */
    @PostMapping("/edit")
    public R<Void> editProIncome(@Validated(edit.class) @RequestBody  ProjectIncomeShowBo income){
        boolean result = baseService.editProIncome(income);
        return result ? R.ok() : R.fail();
    }

    /**
     * 删除
     * @param ids
     * @return
     */
    @ApiOperation("删除")
    @DeleteMapping("/remove/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空") @PathVariable String[] ids)
    {
        boolean result = baseService.delProIncome(Arrays.asList(ids),true);
        return result ? R.ok() : R.fail();
    }

    /**
     * 根据项目id获取页面信息
     * @param showBo
     * @return
     */
    @ApiOperation("根据项目id获取页面信息")
    @GetMapping("/getprojectInfo")
    public R<ProjectIncomeShowVo> getprojectInfo(FundsFeeShowBo showBo){
        return R.ok(baseService.getprojectInfo(showBo));
    }

}
